#
# APM Copter-4.1.2 SITL testing environment for MAVSDK based on Ubuntu 20.04.
# Author: Yogesh Khedar <yogeshkhedar@gmail.com>
#
FROM mavsdk/mavsdk-ubuntu-20.04
MAINTAINER Yogesh Khedar <yogeshkhedar@gmail.com>

ENV FIRMWARE_DIR ${WORKDIR}../ArduPilot

RUN apt-get update && \
    DEBIAN_FRONTEND=noninteractive apt-get --quiet -y --no-install-recommends install locales  \
                                python3 python3-wheel gnupg gcc lcov rsync screen shellcheck psmisc \
                                && apt-get -y autoremove \
                                && apt-get clean autoclean \
                                && rm -rf /var/lib/apt/lists/{apt,dpkg,cache,log} /tmp/* /var/tmp/*

RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
ENV COPTER_VERSION Copter-4.1.2

RUN git clone https://github.com/ArduPilot/ardupilot.git ${FIRMWARE_DIR}
RUN git -C ${FIRMWARE_DIR} checkout ${COPTER_VERSION}
RUN git -C ${FIRMWARE_DIR} submodule update --init --recursive

RUN cd ${FIRMWARE_DIR} && sed -i 's/sudo //' Tools/environment_install/install-prereqs-ubuntu.sh && \
    sed -i '6,9d' Tools/environment_install/install-prereqs-ubuntu.sh && \
    sed -i '/usermod -a -G dialout/d' Tools/environment_install/install-prereqs-ubuntu.sh && \
    sed -i 's/--user//' Tools/environment_install/install-prereqs-ubuntu.sh && \
    bash Tools/environment_install/install-prereqs-ubuntu.sh -y

ENV APM_VEHICLE ArduCopter
ENV APM_FRAME quad

RUN cd ${FIRMWARE_DIR} && ./waf distclean && ./waf configure --board sitl && ./waf copter


